﻿using System;
using System.Text;
using System.Data;

using LTJ.Common.Generic;
using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;

namespace LTJ.Data.DataProvider
{
    /// <summary>
    /// 航线基本信息维护操作
    /// </summary>
    public class RouteBases
    {
        /// <summary>
        /// 创建航线信息
        /// </summary>
        public static int CreateRouteBase(RouteBaseInfo rinfo)
        {
            return DatabaseProvider.GetInstance().CreateRouteBase(rinfo);
        }
        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        public static List<RouteBaseInfo> GetRouteBaseListByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return LoadRouteBaseList(DatabaseProvider.GetInstance().GetRouteBaseListByPage(pageindex, pagesize, condition, ordercolumn, ordertype));
        }

        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        public static List<RouteBaseInfo> GetRouteBaseSearchByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return LoadRouteBaseSearchList(DatabaseProvider.GetInstance().GetRouteBaseSearchByPage(type, oid, cid, pageindex, pagesize, condition, ordercolumn, ordertype));
        }

        /// <summary>
        /// 航线基本信息分页操作(table)
        /// </summary>
        public static DataTable GetRouteBaseSearchTableByPage(int type, int oid, int cid, int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return DatabaseProvider.GetInstance().GetRouteBaseSearchTableByPage(type, oid, cid, pageindex, pagesize, condition, ordercolumn, ordertype);
        }

        /// <summary>
        /// 航线基本信息分页操作
        /// </summary>
        public static DataTable GetRouteBaseTableByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return DatabaseProvider.GetInstance().GetRouteBaseTableByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }
        /// <summary>
        /// 航线数量
        /// </summary>
        public static int GetRouteBasesCount(string conditions)
        {
            return DatabaseProvider.GetInstance().GetRouteBasesCount(conditions);
        }
        /// <summary>
        /// 搜索航线数量
        /// </summary>
        public static int GetRouteBaseListCount(int type, int oid, string conditions)
        {
            return DatabaseProvider.GetInstance().GetRouteBaseListCount(type, oid, conditions);
        }
        /// <summary>
        /// 修改航线信息
        /// </summary>
        /// <param name="rbinfo"></param>
        /// <returns></returns>
        public static int UpdateRouteBase(RouteBaseInfo rbinfo)
        {
            return DatabaseProvider.GetInstance().UpdateRouteBase(rbinfo);
        }
        /// <summary>
        /// 快捷价格修改
        /// </summary>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        public static int UpdateRouteBasePrice(int rid, string price1, string price2, string price3)
        {
            return DatabaseProvider.GetInstance().UpdateRouteBasePrice(rid, price1, price2, price3);
        }
        /// <summary>
        /// 获取航线实体信息
        /// </summary>
        public static RouteBaseInfo GetRouteBaseInfo(int id)
        {
            return LoaSingledRouteBaseList(DatabaseProvider.GetInstance().GetRouteBaseInfo(id));
        }
        /// <summary>
        /// 获取搜索航线实体信息
        /// </summary>
        public static RouteBaseInfo GetSearchRouteBaseInfo(int id, int type, int oid, int cid)
        {
            return LoaSingledRouteBaseSearchList(DatabaseProvider.GetInstance().GetSearchRouteBaseInfo(id, type, oid, cid));
        }
        public static int DelRouteBase(string ids)
        {
            return DatabaseProvider.GetInstance().DelRouteBase(ids);
        }
        public static int UpdateRouteBaseStatus(string ids,int val)
        {
            return DatabaseProvider.GetInstance().UpdateRouteBaseStatus(ids,val);
        }

        /// <summary>
        /// 搜索条件生成
        /// </summary>
        /// <param name="cid">所属公司ID</param>
        /// <param name="isuse">是否启用（-1为不限，0为未启用，1，为启用中）</param>
        /// <param name="loadport">起运港口</param>
        /// <param name="objectport">目的港口</param>
        /// <param name="routeline">航线</param>
        /// <param name="corp">船公司</param>
        public static string GetRouteBaseCondation(int cid, int isuse, string loadport, string objectport, string routeline, string corp)
        {
            return DatabaseProvider.GetInstance().GetRouteBaseCondation(cid, isuse, loadport, objectport, routeline, corp);
        }
        /// <summary>
        /// 批量修改线路价格信息
        /// </summary>
        public static int UpdateBatchRoutePrice(RouteBaseInfo rinfo, string ids)
        {
            return DatabaseProvider.GetInstance().UpdateBatchRoutePrice(rinfo, ids);
        }

        /// <summary>
        /// 批量修改线路基本信息
        /// </summary>
        public static int UpdateBatchRouteInfo(RouteBaseInfo rinfo, string ids)
        {
            return DatabaseProvider.GetInstance().UpdateBatchRouteInfo(rinfo, ids);
        }
        #region helper
        private static RouteBaseInfo LoaSingledRouteBaseList(IDataReader reader)
        {
            RouteBaseInfo _info = null;
            if (reader.Read())
            {
                _info = new RouteBaseInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.loadport = reader["loadport"].ToString();
                _info.destport = reader["destport"].ToString();
                _info.tranport = reader["tranport"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.pier = reader["pier"].ToString();
                _info.schbegin = reader["schbegin"].ToString();
                _info.schend = reader["schend"].ToString();
                _info.range = reader["range"].ToString();
                _info.validbegin = Utils.GetStandardDate(reader["validbegin"].ToString());
                _info.validend = Utils.GetStandardDate(reader["validend"].ToString());
                _info.bio = reader["bio"].ToString();
                _info.cid = TypeConverter.ObjectToInt(reader["cid"]);
                _info.uid = TypeConverter.ObjectToInt(reader["uid"]);
                _info.createdate = Utils.GetStandardDate(reader["createdate"].ToString());
                _info.backup = reader["backup"].ToString();
                _info.isuse = TypeConverter.ObjectToInt(reader["isuse"], 1);

                _info.loadname = reader["loadname"].ToString();
                _info.loadename = reader["loadename"].ToString();
                _info.destname = reader["destname"].ToString();
                _info.destename = reader["destename"].ToString();
                _info.tranname = reader["tranname"].ToString();
                _info.tranename = reader["tranename"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.bename = reader["bename"].ToString();
                _info._20GP = reader["20GP"].ToString();
                _info._40GP = reader["40GP"].ToString();
                _info._40HQ = reader["40HQ"].ToString();
                _info.YAS = reader["YAS"].ToString();
                _info.CIC = reader["CIC"].ToString();
                _info.EBS = reader["EBS"].ToString();
                _info.PSS = reader["PSS"].ToString();
                _info.OTHER = reader["OTHER"].ToString();
                _info.CAF = reader["CAF"].ToString();
                _info.BAF = reader["BAF"].ToString();
                _info.AMS_ENS = reader["AMS_ENS"].ToString();
                _info.QFF = reader["QFF"].ToString();
                _info.DCF = reader["DCF"].ToString();
                _info.XSF = reader["XSF"].ToString();
                _info.THC = reader["THC"].ToString();
                _info.ECR = reader["ECR"].ToString();
                _info.RMB_EBS = reader["RMB_EBS"].ToString();
                _info.DOC = reader["DOC"].ToString();
                _info.RMB_CIC = reader["RMB_CIC"].ToString();
                _info.isconfim = TypeConverter.StrToBool(reader["isconfim"].ToString(), false) ? 1 : 0;
                _info.Extend2 = reader["Extend2"].ToString();
                _info.Extend1 = reader["Extend1"].ToString();
                _info.checkstatus = TypeConverter.ObjectToInt(reader["checkstatus"]);
                _info.routenum = reader["routenum"].ToString();

                _info.routeid = TypeConverter.ObjectToInt(reader["routeid"]);
                _info.routeseaname = reader["routeseaname"].ToString();
                _info.routeseaename = reader["routeseaename"].ToString();
                _info.routebname = reader["routebname"].ToString();
                _info.routebename = reader["routebename"].ToString();

                _info.cname = reader["cname"].ToString();
                _info.ecname = reader["ecname"].ToString();
                _info.relater = reader["relater"].ToString();
                _info.phone = reader["phone"].ToString();

                _info.routebcode = reader["routebcode"].ToString();
                _info.routetcode = reader["routetcode"].ToString();

                if (Users.IsExistField(reader, "seacode")) _info.seacode = reader["seacode"].ToString();
                if (Users.IsExistField(reader, "seaname")) _info.seaname = reader["seaname"].ToString();
                if (Users.IsExistField(reader, "seaename")) _info.seaename = reader["seaename"].ToString();
            }
            reader.Close();
            return _info;
        }
        private static List<RouteBaseInfo> LoadRouteBaseList(IDataReader reader)
        {
            List<RouteBaseInfo> rblist = new List<RouteBaseInfo>();
            while (reader.Read())
            {
                RouteBaseInfo _info = new RouteBaseInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.loadport = reader["loadport"].ToString();
                _info.destport = reader["destport"].ToString();
                _info.tranport = reader["tranport"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.pier = reader["pier"].ToString();
                _info.schbegin = reader["schbegin"].ToString();
                _info.schend = reader["schend"].ToString();
                _info.range = reader["range"].ToString();
                _info.validbegin = Utils.GetStandardDate(reader["validbegin"].ToString());
                _info.validend = Utils.GetStandardDate(reader["validend"].ToString());
                _info.bio = reader["bio"].ToString();
                _info.cid = TypeConverter.ObjectToInt(reader["cid"]);
                _info.uid = TypeConverter.ObjectToInt(reader["uid"]);
                _info.createdate = Utils.GetStandardDate(reader["createdate"].ToString());
                _info.backup = reader["backup"].ToString();
                _info.isuse = TypeConverter.ObjectToInt(reader["isuse"], 1);
                _info.routenum = reader["routenum"].ToString();

                _info.loadname = reader["loadname"].ToString();
                _info.loadename = reader["loadename"].ToString();
                _info.destname = reader["destname"].ToString();
                _info.destename = reader["destename"].ToString();
                _info.tranname = reader["tranname"].ToString();
                _info.tranename = reader["tranename"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.bename = reader["bename"].ToString();
                _info._20GP = reader["20GP"].ToString();
                _info._40GP = reader["40GP"].ToString();
                _info._40HQ = reader["40HQ"].ToString();
                _info.YAS = reader["YAS"].ToString();
                _info.CIC = reader["CIC"].ToString();
                _info.EBS = reader["EBS"].ToString();
                _info.PSS = reader["PSS"].ToString();
                _info.OTHER = reader["OTHER"].ToString();
                _info.CAF = reader["CAF"].ToString();
                _info.BAF = reader["BAF"].ToString();
                _info.AMS_ENS = reader["AMS_ENS"].ToString();
                _info.QFF = reader["QFF"].ToString();
                _info.DCF = reader["DCF"].ToString();
                _info.XSF = reader["XSF"].ToString();
                _info.THC = reader["THC"].ToString();
                _info.ECR = reader["ECR"].ToString();
                _info.RMB_EBS = reader["RMB_EBS"].ToString();
                _info.DOC = reader["DOC"].ToString();
                _info.RMB_CIC = reader["RMB_CIC"].ToString();
                _info.isconfim = TypeConverter.StrToBool(reader["isconfim"].ToString(), false) ? 1 : 0;
                _info.Extend2 = reader["Extend2"].ToString();
                _info.Extend1 = reader["Extend1"].ToString();
                _info.checkstatus = TypeConverter.ObjectToInt(reader["checkstatus"]);

                _info.routeid = TypeConverter.ObjectToInt(reader["routeid"]);
                _info.routeseaname = reader["routeseaname"].ToString();
                _info.routeseaename = reader["routeseaename"].ToString();
                _info.routebname = reader["routebname"].ToString();
                _info.routebename = reader["routebename"].ToString();
                rblist.Add(_info);
            }
            reader.Close();
            return rblist;
        }
        private static RouteBaseInfo LoaSingledRouteBaseSearchList(IDataReader reader)
        {
            RouteBaseInfo _info = null;
            if (reader.Read())
            {
                _info = new RouteBaseInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.loadport = reader["loadport"].ToString();
                _info.destport = reader["destport"].ToString();
                _info.tranport = reader["tranport"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.pier = reader["pier"].ToString();
                _info.schbegin = reader["schbegin"].ToString();
                _info.schend = reader["schend"].ToString();
                _info.range = reader["range"].ToString();
                _info.validbegin = Utils.GetStandardDate(reader["validbegin"].ToString());
                _info.validend = Utils.GetStandardDate(reader["validend"].ToString());
                _info.bio = reader["bio"].ToString();
                _info.cid = TypeConverter.ObjectToInt(reader["cid"]);
                _info.uid = TypeConverter.ObjectToInt(reader["uid"]);
                _info.createdate = Utils.GetStandardDate(reader["createdate"].ToString());
                _info.backup = reader["backup"].ToString();
                _info.isuse = TypeConverter.ObjectToInt(reader["isuse"], 1);
                _info.routenum = reader["routenum"].ToString();

                _info.loadname = reader["loadname"].ToString();
                _info.loadename = reader["loadename"].ToString();
                _info.destname = reader["destname"].ToString();
                _info.destename = reader["destename"].ToString();
                _info.tranname = reader["tranname"].ToString();
                _info.tranename = reader["tranename"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.bename = reader["bename"].ToString();
                _info._20GP = reader["20GP"].ToString();
                _info._40GP = reader["40GP"].ToString();
                _info._40HQ = reader["40HQ"].ToString();
                _info.YAS = reader["YAS"].ToString();
                _info.CIC = reader["CIC"].ToString();
                _info.EBS = reader["EBS"].ToString();
                _info.PSS = reader["PSS"].ToString();
                _info.OTHER = reader["OTHER"].ToString();
                _info.CAF = reader["CAF"].ToString();
                _info.BAF = reader["BAF"].ToString();
                _info.AMS_ENS = reader["AMS_ENS"].ToString();
                _info.QFF = reader["QFF"].ToString();
                _info.DCF = reader["DCF"].ToString();
                _info.XSF = reader["XSF"].ToString();
                _info.THC = reader["THC"].ToString();
                _info.ECR = reader["ECR"].ToString();
                _info.RMB_EBS = reader["RMB_EBS"].ToString();
                _info.DOC = reader["DOC"].ToString();
                _info.RMB_CIC = reader["RMB_CIC"].ToString();
                _info.isconfim = TypeConverter.StrToBool(reader["isconfim"].ToString(), false) ? 1 : 0;
                _info.Extend2 = reader["Extend2"].ToString();
                _info.Extend1 = reader["Extend1"].ToString();
                _info.checkstatus = TypeConverter.ObjectToInt(reader["checkstatus"]);

                _info.routeid = TypeConverter.ObjectToInt(reader["routeid"]);
                _info.routeseaname = reader["routeseaname"].ToString();
                _info.routeseaename = reader["routeseaename"].ToString();
                _info.routebname = reader["routebname"].ToString();
                _info.routebename = reader["routebename"].ToString();
                _info.routebcode = reader["routebcode"].ToString();
                _info.routetcode = reader["routetcode"].ToString();

                _info._20GP1 = reader["20GP1"].ToString();
                _info._20GP2 = reader["20GP2"].ToString();
                _info._40GP1 = reader["40GP1"].ToString();
                _info._40GP2 = reader["40GP2"].ToString();
                _info._40HQ1 = reader["40HQ1"].ToString();
                _info._40HQ2 = reader["40HQ2"].ToString();

                _info.cname = reader["cname"].ToString();
                _info.ecname = reader["ecname"].ToString();
                _info.relater = reader["relater"].ToString();
                _info.phone = reader["phone"].ToString();

                if (Users.IsExistField(reader, "20GP3")) _info._20GP3 = reader["20GP3"].ToString();
                if (Users.IsExistField(reader, "40GP3")) _info._40GP3 = reader["40GP3"].ToString();
                if (Users.IsExistField(reader, "40HQ3")) _info._40HQ3 = reader["40HQ3"].ToString();
                if (Users.IsExistField(reader, "20GP4")) _info._20GP4 = reader["20GP4"].ToString();
                if (Users.IsExistField(reader, "40GP4")) _info._40GP4 = reader["40GP4"].ToString();
                if (Users.IsExistField(reader, "40HQ4")) _info._40HQ4 = reader["40HQ4"].ToString();

                if (Users.IsExistField(reader, "20GP0")) _info._20GP0 = reader["20GP0"].ToString();
                if (Users.IsExistField(reader, "40GP0")) _info._40GP0 = reader["40GP0"].ToString();
                if (Users.IsExistField(reader, "40HQ0")) _info._40HQ0 = reader["40HQ0"].ToString();

                if (Users.IsExistField(reader, "20GP5")) _info._20GP5 = reader["20GP5"].ToString();
                if (Users.IsExistField(reader, "40GP5")) _info._40GP5 = reader["40GP5"].ToString();
                if (Users.IsExistField(reader, "40HQ5")) _info._40HQ5 = reader["40HQ5"].ToString();
                if (Users.IsExistField(reader, "20GP6")) _info._20GP6 = reader["20GP6"].ToString();
                if (Users.IsExistField(reader, "40GP6")) _info._40GP6 = reader["40GP6"].ToString();
                if (Users.IsExistField(reader, "40HQ6")) _info._40HQ6 = reader["40HQ6"].ToString();
            }
            reader.Close();
            return _info;
        }
        private static List<RouteBaseInfo> LoadRouteBaseSearchList(IDataReader reader)
        {
            List<RouteBaseInfo> rblist = new List<RouteBaseInfo>();
            while (reader.Read())
            {
                RouteBaseInfo _info = new RouteBaseInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.loadport = reader["loadport"].ToString();
                _info.destport = reader["destport"].ToString();
                _info.tranport = reader["tranport"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.pier = reader["pier"].ToString();
                _info.schbegin = reader["schbegin"].ToString();
                _info.schend = reader["schend"].ToString();
                _info.range = reader["range"].ToString();
                _info.validbegin = Utils.GetStandardDate(reader["validbegin"].ToString());
                _info.validend = Utils.GetStandardDate(reader["validend"].ToString());
                _info.bio = reader["bio"].ToString();
                _info.cid = TypeConverter.ObjectToInt(reader["cid"]);
                _info.uid = TypeConverter.ObjectToInt(reader["uid"]);
                _info.createdate = Utils.GetStandardDate(reader["createdate"].ToString());
                _info.backup = reader["backup"].ToString();
                _info.isuse = TypeConverter.ObjectToInt(reader["isuse"], 1);
                _info.routenum = reader["routenum"].ToString();

                _info.loadname = reader["loadname"].ToString();
                _info.loadename = reader["loadename"].ToString();
                _info.destname = reader["destname"].ToString();
                _info.destename = reader["destename"].ToString();
                _info.tranname = reader["tranname"].ToString();
                _info.tranename = reader["tranename"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.bename = reader["bename"].ToString();
                _info._20GP = reader["20GP"].ToString();
                _info._40GP = reader["40GP"].ToString();
                _info._40HQ = reader["40HQ"].ToString();
                _info.YAS = reader["YAS"].ToString();
                _info.CIC = reader["CIC"].ToString();
                _info.EBS = reader["EBS"].ToString();
                _info.PSS = reader["PSS"].ToString();
                _info.OTHER = reader["OTHER"].ToString();
                _info.CAF = reader["CAF"].ToString();
                _info.BAF = reader["BAF"].ToString();
                _info.AMS_ENS = reader["AMS_ENS"].ToString();
                _info.QFF = reader["QFF"].ToString();
                _info.DCF = reader["DCF"].ToString();
                _info.XSF = reader["XSF"].ToString();
                _info.THC = reader["THC"].ToString();
                _info.ECR = reader["ECR"].ToString();
                _info.RMB_EBS = reader["RMB_EBS"].ToString();
                _info.DOC = reader["DOC"].ToString();
                _info.RMB_CIC = reader["RMB_CIC"].ToString();
                _info.isconfim = TypeConverter.StrToBool(reader["isconfim"].ToString(), false) ? 1 : 0;
                _info.Extend2 = reader["Extend2"].ToString();
                _info.Extend1 = reader["Extend1"].ToString();
                _info.checkstatus = TypeConverter.ObjectToInt(reader["checkstatus"]);

                _info.routeid = TypeConverter.ObjectToInt(reader["routeid"]);
                _info.routeseaname = reader["routeseaname"].ToString();
                _info.routeseaename = reader["routeseaename"].ToString();
                _info.routebname = reader["routebname"].ToString();
                _info.routebename = reader["routebename"].ToString();

                _info._20GP1 = reader["20GP1"].ToString();
                _info._20GP2 = reader["20GP2"].ToString();
                _info._40GP1 = reader["40GP1"].ToString();
                _info._40GP2 = reader["40GP2"].ToString();
                _info._40HQ1 = reader["40HQ1"].ToString();
                _info._40HQ2 = reader["40HQ2"].ToString();

                _info.cname = reader["cname"].ToString();
                _info.ecname = reader["ecname"].ToString();
                _info.relater = reader["relater"].ToString();
                _info.phone = reader["phone"].ToString();

                _info.contryname = reader["countryname"].ToString();
                _info.contryename = reader["countryename"].ToString();

                if (Users.IsExistField(reader, "20GP3")) _info._20GP3 = reader["20GP3"].ToString();
                if (Users.IsExistField(reader, "40GP3")) _info._40GP3 = reader["40GP3"].ToString();
                if (Users.IsExistField(reader, "40HQ3")) _info._40HQ3 = reader["40HQ3"].ToString();
                if (Users.IsExistField(reader, "20GP4")) _info._20GP4 = reader["20GP4"].ToString();
                if (Users.IsExistField(reader, "40GP4")) _info._40GP4 = reader["40GP4"].ToString();
                if (Users.IsExistField(reader, "40HQ4")) _info._40HQ4 = reader["40HQ4"].ToString();

                if (Users.IsExistField(reader, "20GP0")) _info._20GP0 = reader["20GP0"].ToString();
                if (Users.IsExistField(reader, "40GP0")) _info._40GP0 = reader["40GP0"].ToString();
                if (Users.IsExistField(reader, "40HQ0")) _info._40HQ0 = reader["40HQ0"].ToString();

                if (Users.IsExistField(reader, "20GP5")) _info._20GP5 = reader["20GP5"].ToString();
                if (Users.IsExistField(reader, "40GP5")) _info._40GP5 = reader["40GP5"].ToString();
                if (Users.IsExistField(reader, "40HQ5")) _info._40HQ5 = reader["40HQ5"].ToString();
                if (Users.IsExistField(reader, "20GP6")) _info._20GP6 = reader["20GP6"].ToString();
                if (Users.IsExistField(reader, "40GP6")) _info._40GP6 = reader["40GP6"].ToString();
                if (Users.IsExistField(reader, "40HQ6")) _info._40HQ6 = reader["40HQ6"].ToString();

                rblist.Add(_info);
            }
            reader.Close();
            return rblist;
        }
        #endregion
    }
}
